(function($){

    $("[menu-url]").on("click",function(obj){
        $("[menu-url]").each(function(){
            $(this).removeClass("active");
        });
        $(obj.currentTarget).addClass("active");
        $.get(window.BASETATH+$(obj.currentTarget).attr("menu-url")+".html",function(html){
            $(".content-wrapper").html(html);
        });
    });

    restAjax("index",window.RequestMethod.GET,{success:function(data){
        $("#userName").text(data.data.nickName);
    }});

    $("#logout").on("click",function(){
        restAjax("login/logout",window.RequestMethod.GET,{success:function(data){
            window.location.href = window.BASETATH;
        }});
    });

    $("#showUpdatePwd").on("click",function(){
        $('#pwdDiv').modal({backdrop:false});
    });

    $("#ownUpgrade").on("click",function(){
        window.Dialog.prompt({
            title:"自我修复",
            func:function(remark){
                restAjax("index/ownUpgrade",window.RequestMethod.GET,{
                    data:{remark:remark},
                    success:function(data){

                    }
                });
            }
        })
    });

    $("#savePwd").on("click",function(){
        if($("#pwdForm").valid()){
            if($("#newPwd").val()!==$("#rePwd").val()){
                window.Dialog.alert("两次输入密码不正确!");
                return;
            }
            restAjax("user/updatePwd",window.RequestMethod.POST,{formId:"pwdForm",success:function(data){
                if(!data.suc){
                    window.Dialog.alert(data.message);
                }else{
                    $('#pwdDiv').modal('hide')
                }
            }});
        }    });

    $("#pwdForm").validation({icon:true});

    $("[menu-url]:first").click();
})(jQuery);